package cn.kimming.wms.domain;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import lombok.Getter;
import lombok.Setter;

public class Employee extends BaseDomain{
	@Getter @Setter
	private String name;
	@Getter @Setter
	private String password;
	@Getter @Setter
	private String email;
	@Getter @Setter
	private Integer age;
	@Getter @Setter
	private boolean admin;
	
	
	@Getter @Setter
	private Department dept;	//many2one, dept_id
	
	@Getter @Setter
	private List<Role> roles = new ArrayList<>();	//角色列表, many2many, employee_role

	@Override
	public String toString() {
		return "Employee [name=" + name + ", password=" + password + ", email=" + email + ", age=" + age + ", admin="
				+ admin + "]";
	}	
	
	
	public String getRoleName() {
		if (admin) {
			return "超级管理员";
		}
		if (roles.size() == 0) {
			return "暂无角色";
		}
		List<String> rnames = new ArrayList<>();
		for (Role role : roles) {
			rnames.add(role.getName());
		}
		return StringUtils.join(rnames, "|");
	}
	
}
